package com.example.wangfanwangluo.wangfanboss;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.Toast;

import com.example.wangfanwangluo.wangfanboss.Adapters.FacheAdapter;
import com.example.wangfanwangluo.wangfanboss.Models.FacheModel;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wanghouyi on 2017/11/28.
 */

public class DaocheFragment extends Fragment {

    private ListView lv;
    private FacheAdapter adapter;
    private List<FacheModel> list = new ArrayList<>();

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        //定义跟踪fragment，使与fragment_fache.xml相对应
        return inflater.inflate(R.layout.fragment_daoche, container, false);

    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        //数据
        loadData();
        //视图，传递数据
        initViews();
    }

    private void loadData() {
        for (int i = 1; i <= 20; i++) {
            if (i % 2 == 1) {
                FacheModel firstModel = new FacheModel("津BMW123","天津","石家庄","王晓静",
                        "12/30 10:00","1000","已到车","17610939328+" + String.valueOf(i));
                list.add(firstModel);
            }else {
                FacheModel secondModel = new FacheModel("京ABC123","北京","上海","张晓丽",
                        "01/01 10:00","2000","已到车","15641248533+" + String.valueOf(i));
                list.add(secondModel);
            }

        }
    }

    private void initViews() {
        adapter = new FacheAdapter(getActivity(),list);
        lv = (ListView)getActivity().findViewById(R.id.listview_daoche);
        lv.setAdapter(adapter);
        adapter.setObjOnCallDriverAction(new FacheAdapter.onCallDriverAction() {
            @Override
            public void onCallDriverAction(String i) {
                Toast.makeText(getActivity(),i, Toast.LENGTH_SHORT).show();
            }
        });
    }


}
